package com.yuanchuang.yp.framework.common;

import java.io.Serializable;

/**
 * 10^7 以上已经分配了
 *
 * @author Dreampie
 * @date 2015-07-06
 * @what 编码和信息
 */
public enum CommonCode implements Serializable {
    OK(200, "OK"),
    BAD_REQUEST(400, "请求错误"),
    UNAUTHORIZED(401, "未认证"),
    FORBIDDEN(403, "没有权限访问"),
    NOT_FOUND(404, "请求资源不存在"),
    TOO_MANY_REQUESTS(405, "请求次数超过限制"),
    UNPROCESSABLE_ENTITY(422, "请求参数错误"),
    INTERNAL_SERVER_ERROR(500, "服务器错误"),
    SERVICE_UNAVAILABLE(503, "接口不存在或无效"),
    THIRD_SERVER_ERROR(504, "第三方服务器错误"),

    USERNAME_ERROR(400001, "用户名错误"),
    USER_ERROR_PASSWARD(410002, "用户密码错误"),
    USER_EXISTS(410003, "用户已存在"),
    PERMISSION_EXISTS(410004, "权限已存在"),
    ROLE_EXISTS(410005, "角色已存在"),
    ROLE_DENIED(410006, "用户不能修改角色"),
    LOGGER_TYPE_EXISTS(410007, "权限类型已存在"),
    USER_NOT_EXISTS(410008, "用户不存在"),
    USER_LOCKED(410009, "用户被锁定"),

    INTERFACE_PARAMETER_EXISTS(510001, "这个地址参数已经有了! ( ⊙ o ⊙ )"),

    MD5_SIGN_ERROR(500001, "MD5加密错误"),

    GAME_ERROR_REMOTE(600000, "remote服务未知错误"),
    GAME_ERROR_REMOTE_CONNECT(600001, "remote服务IO错误"),
    GAME_ERROR_REMOTE_URI(600002, "remote服务URI错误");

    /***
     *
     * import from
     */
    private int code;
    private String message;

    private CommonCode(int code, String messasge) {
        this.code = code;
        this.message = messasge;
    }

    public static CommonCode codeOf(int code) {
        for (CommonCode apiCode : values()) {
            if (apiCode.code == code) {
                return apiCode;
            }
        }
        throw new IllegalArgumentException("Invalid HTTP Status code : " + code);
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }
}
